home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: more problems with qsort
- Date: 3 Mar 1996 00:29:13 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4hbe7p$reg@solutions.solon.com>
- References: <177399702S86.JW1675A@american.edu> <4h0j9e$ng5@clarknet.clark.net> <4h81m0$avr@solutions.solon.com> <4hba5n$2ga@clarknet.clark.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4hba5n$2ga@clarknet.clark.net>, yom <yom@clark.net> wrote:
- >In article <4h81m0$avr@solutions.solon.com>, seebs@solutions.solon.com
- >says...
- >>>And your compare function must be defined like this:
-
- >>>int compare(char **a,char **b) {return strcmp(*a,*b);}
-
- >>No, it really mustn't. It must be defined like this:
- >>int compare(const void *a, const void *b) {
- >> return strcmp(*(char **) a, *(char **) b);
- >>}
-
- >Well I disagree on this one.
-
- Then you are wrong.
-
- Calling conventions for functions may vary by type of arguments; the
- qsort() function will pass pointers into the compare function as
- (void *). If the cast is nontrivial, which it may be on some systems,
- then if the function does not cast the arguments, it looses.
-
- >Also, I tend to not use "const" because some compilers do
- >not support it.
-
- But a compiler may legitimately reject the code for incompatabilities
- if you omit the const.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-